<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();

$tabs=array(
	array('op'=>'list','title'=>'分润列表'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['orderid']){
		$params['orderid']=intval($_RQ['orderid']);
		$return['params']['orderid']=$_RQ['orderid'];
	}
    if(!empty($_RQ['expresssn'])){
        $params2=array('uniacid'=>$_SESSION['uniacid']);
        $params2['expresssn like']='%'.trim($_RQ['expresssn']).'%';
        $orderids=pdo_getall('jy_kuaidisys_jilog',$params2,array('id'),'id');
        if($orderids){
            $orderids=array_keys($orderids);
        }else{
            $orderids=-1;
        }
        $params['orderid']=$orderids;
        $return['params']['expresssn']=$_RQ['expresssn'];
    }
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'分销员长','type'=>'member'),
			array('name'=>'orderid','title'=>'订单ID','type'=>'string'),
			array('name'=>'money','title'=>'分润','type'=>'string'),
			array('name'=>'type','title'=>'分润类型','type'=>'radio','options'=>'types'),
			array('name'=>'commission_type','title'=>'分润计算方式','type'=>'radio','options'=>'commissiontypes'),
			array('name'=>'level','title'=>'站长等级','type'=>'select','options'=>'levels'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
			array('name'=>'status','title'=>'分润状态','type'=>'radio','options'=>'commission_status'),		
			array('name'=>'balancesn','title'=>'结算单号','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal','op'=>'detail','title'=>'分润详情'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'name'=>'orderid','title'=>'订单ID'),
            array('name'=>'expresssn','width'=>15,'title'=>'快递单号','type'=>'string'),
			array('type'=>'choose','width'=>18,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'分润状态','options'=>'commission_status'),
		),
	);
	$return['htmls']=$htmls;
	$return['commission_status']=$this->commission_status;
	$return['commissiontypes']=$this->commission_types2;
	$return['types']=$this->commission_feetypes;
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['levels']['0']=array('id'=>'0','title'=>'默认等级');
	exi($return);
}
if($_RQ['op']=='detail'){
	$item=$this->get('commission',array('id'=>intval($_RQ['id'])),array('id','remark'));
	if(!$item){
		exi('指定分润不存在！','error');
	}
	$item['remark']=$this->model('commission')->commission_remark($item['remark']);
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'分润明细',
		'look'=>array(
			array('type'=>'text','name'=>'remark','title'=>'分润明细'),
		),
	);
	exi($return);
}